using System;
using MoonFramework.Scripts.Event;
using MoonFramework.Template;
using UnityEngine;

namespace MoonFramework.Scripts.View.UI
{
	/// <summary>
	///     窗口结果
	/// </summary>
	public enum WindowResult
    {
        None,
        Yes,
        No
    }

	/// <summary>
	///     窗口基类
	/// </summary>
	public class BaseUIWindow : MonoBehaviour
    {
        // 窗口类型
        public Type Type => GetType();

        /// <summary>
        ///     初始化
        /// </summary>
        public virtual void Init()
        {
            RegisterEvent();
        }

        /// <summary>
        ///     显示
        /// </summary>
        public virtual void Show()
        {
            SendEvent();
        }

        /// <summary>
        ///     关闭
        /// </summary>
        public virtual void Close()
        {
            UIManager.Instance.Close(Type);
            CancelEventListener();
        }

        /// <summary>
        ///     点击 是 / 确认
        /// </summary>
        public virtual void OnCloseClick()
        {
            Close();
        }

        /// <summary>
        ///     点击 否 / 取消
        /// </summary>
        public virtual void OnYesClick()
        {
            Close();
        }

        /// <summary>
        ///     注册事件
        /// </summary>
        protected virtual void RegisterEvent()
        {
            EventCenter.Instance.Register("UpdateLanguage");
        }

        /// <summary>
        ///     发送事件
        /// </summary>
        protected virtual void SendEvent()
        {
            EventCenter.Instance.SendCommand("UpdateLanguage", OnUpdateLanguage);
        }

        /// <summary>
        ///     取消事件
        /// </summary>
        protected virtual void CancelEventListener()
        {
            EventCenter.Instance.RemoveCommand("UpdateLanguage", OnUpdateLanguage);
        }

        protected virtual void OnUpdateLanguage()
        {
        }

        protected virtual void OnDestroy()
        {
            CancelEventListener();
        }
    }
}